package com.hot100;

import java.util.Arrays;

public class Solution621 {
    public int leastInterval(char[] tasks, int n) {
        int[] count = new int[26];
        int max = 1;
        int maxNum = 0;
        for (int i = 0; i < tasks.length; i++) {
            count[tasks[i] - 'A']++;
            if (count[tasks[i] - 'A'] > max) {
                max = count[tasks[i] - 'A'];
                maxNum = 1;
            } else if (count[tasks[i] - 'A'] == max) maxNum++;
        }
        return Math.max(tasks.length, (n + 1) * (max - 1) + maxNum);
    }
}
